﻿Namespace Attributes
    <System.AttributeUsage(System.AttributeTargets.Property, AllowMultiple:=False, Inherited:=True), System.Serializable()> _
    Public Class IsCollectionAttribute
        Inherits Attribute
        Implements IPropertyAttribute

        Private _ForeingTableName As String
        Public Property ForeingTableName() As String
            Get
                Return _ForeingTableName
            End Get
            Set(ByVal value As String)
                _ForeingTableName = value
            End Set
        End Property

        'Private _ForeingMappField As String
        'Public Property ForeingMappField() As String
        '    Get
        '        Return _ForeingMappField
        '    End Get
        '    Set(ByVal value As String)
        '        _ForeingMappField = value
        '    End Set
        'End Property

        'Private _EntityClassName As String
        'Public Property EntityClassName() As String
        '    Get
        '        Return _EntityClassName
        '    End Get
        '    Set(ByVal value As String)
        '        _EntityClassName = value
        '    End Set
        'End Property

        Sub New(ByVal foreingTableName As String, ByVal MapsFieldsCommaSeparated As String)
            Me.ForeingTableName = foreingTableName
            If MapsFieldsCommaSeparated.Contains(",") Then
                Dim v = MapsFieldsCommaSeparated.Split(",")
                For i As Integer = 0 To v.Length - 2
                    If (MappedFields Is Nothing) Then
                        MappedFields = New List(Of MappFields)
                        MappedFields.Add(New MappFields(v(i).Trim(), v(i + 1).Trim()))
                    End If
                Next

            Else

                If (MappedFields Is Nothing) Then
                    MappedFields = New List(Of MappFields)
                    MappedFields.Add(New MappFields(MapsFieldsCommaSeparated, MapsFieldsCommaSeparated))
                End If
            End If

        End Sub


        Private _MappedFields As List(Of MappFields)
        Public Property MappedFields() As List(Of MappFields)
            Get
                Return _MappedFields
            End Get
            Set(ByVal value As List(Of MappFields))
                _MappedFields = value
            End Set
        End Property

        Public Class MappFields
            Public ThisField As String
            Public ForeingField As String
            Public Sub New(ByVal _ThisField As String, ByVal _ForeingField As String)
                Me.ThisField = _ThisField
                Me.ForeingField = _ForeingField
            End Sub
        End Class



    End Class
End Namespace

